<?php
Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('static-page-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<div class="well well-small widget-box dataTables_wrapper">
	<?php echo GxHtml::link(Yii::t('app', 'Advanced Search'), '#', array('class' => 'search-button')); ?>
	<div class="search-form" style="display: none">
	<?php $this->renderPartial('_search', array(
		'model' => $model,
	)); ?>
	</div><!-- search-form -->
</div>
<div class="widget-box dataTables_wrapper">

	<?php $form=$this->beginWidget('CActiveForm', array(
			'id'=>'static-page-form',
			'action' => 'admin',
			'htmlOptions'=>array(
					'class'=>'jform',
			),

	)); ?>
		
		<?php 
		//$this->widget('zii.widgets.grid.CGridView', array(
		$this->widget('ext.selgridview.SelGridView', array(
			'id' => 'static-pages-grid',
			'dataProvider' => $model->search(),
			'template' => count($model->search()->getData())==0?'{items}':'{items}<div class="fg-toolbar widget-content"><a class="btn btn-primary" href="#" onclick="return actionDelete();">Delete</a>{pager}{summary}</div>',
			'selectableRows'=>count($model->search()->getData()),
			'itemsCssClass'=>'table table-bordered table-striped table-hover',
			'summaryCssClass'=>'summary widget-title',
			'cssFile'=> Yii::app()->request->baseUrl.WWWROOT_BACKEND."/css/gridview/styles.css",
			'htmlOptions'=>array('class'=>'widget-content nopadding grid-view'),
			'filter' => $model,
			'columns' => array(
				array(
						'class' => 'CCheckBoxColumn',
						'htmlOptions' => array('class'=>'jform'),
						'headerHtmlOptions' => array('class' => 'jform jlb_checkbox_check_all jlb_checkbox_check_all_disable'),
						'header' => '<input type="checkbox" class="select-on-check-all"/>',
						'value' => '$data->primaryKey',
				),
				//'id',
				array(
						'name' => 'title',
						'htmlOptions'=>array('style'=>'width:150px;'),
				),
				array(
						'name' => 'alias',
						'htmlOptions'=>array('style'=>'width:150px;'),
				),
				/*
				array(
						'name' => 'image',
						'type' => 'html',
						//'value' => '(!empty($data->image) && file_exists(Yii::app()->createUrl("/")."/wwwroot/upload_files/static_pages/thumb_".$data->image))? Yii::app()->createUrl("/")."/wwwroot/upload_files/static_pages/thumb_".$data->image : Yii::app()->createUrl("/")."/wwwroot/upload_files/static_pages/no-image.jpg"',
						
						'value'=>'(!empty($data->image) && file_exists(Yii::app()->createUrl("/"). Yii::app()->controller->module->image["uri"]."thumb_".$data->image))?CHtml::image(Yii::app()->createUrl("/").Yii::app()->controller->module->image["url"]."thumb_".$data->image, "", array("style" => "width: 100px; height: 70px;")) : CHtml::image(Yii::app()->createUrl("/").Yii::app()->controller->module->image["url"]."no-image.jpg", "", array("style" => "width: 100px; height: 70px;"))',
						
						'htmlOptions' => array('style' => 'width: 110px;'),
				),
				*/
				//'description',
				/*
				array(
						'name' => 'description',
						'type' => 'html',
						'value'=>'strip_tags($data->description)'
				),
				array(
						'name' => 'show_on_index',
						'htmlOptions'=>array('style'=>'width:60px;'),
						'value' => '($data->show_on_index == 0) ? Yii::t(\'app\', \'No\') : Yii::t(\'app\', \'Yes\')',
						'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),
				),
				*/
				array(
					'name' => 'modified',
					'value' => '$data->modified',
				),
				array(
					'name' => 'created',
					'value' => '$data->created',
				),
				array(
						'name' => 'is_published',
						'header'	=> 'Publish?',
						'htmlOptions'=>array('style'=>'width:60px;'),
						'value' => '($data->is_published == 0) ? Yii::t(\'app\', \'No\') : Yii::t(\'app\', \'Yes\')',
						'filter' => array('0' => Yii::t('app', 'No'), '1' => Yii::t('app', 'Yes')),
				),
				array(
					'class' => 'CButtonColumn',
				),
			),
		)); ?>
		
	<?php $this->endWidget(); ?>
</div>
<script type="text/javascript">
	function actionDelete()
	{
		if ($("input:checkbox[name='static-pages-grid_c0[]']:checked").length == 0) {
			alert('<?php echo 'Please select at least one item to remove.'; ?>');
			return false;
		}
		if (confirm('<?php echo 'Are you sure you want to delete?'; ?>')) $('#static-page-form').submit();
		return false;
	}
	</script>